<template>
  <div class="login-sms">
    <el-form :model="form" :rules="rules">
      <el-form-item>
        <h1>令牌登录</h1>
      </el-form-item>
      <el-form-item prop="account">
        <el-input
          v-model="form.account"
          placeholder="请输入账号或者手机号"
        ></el-input>
      </el-form-item>
      <el-form-item class="captcha" prop="captcha">
        <el-input placeholder="验证码6位" v-model.number="form.captcha">
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary">令牌登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
// 1.将文字改为模型数据 <el-button slot="append">获取验证码</el-button>
// 2.绑定点击事件
//    2.1定时器每隔1秒
//    2.2修改模型数据
//    2.3当数据为零时，清除定时器 重新改为 获取验证码

//验证： 1 v-model 2 ：model、：rules、prop
export default {
  data() {
    const checkaccount = (rule, value, callback) => {
      // 检查是否是纯数字
      // 是 走手机判断
      // 不是 走账号判断
      if (/^\d+$/g.test(value)) {
        if (/^1\d{10}$/g.test(value)) {
          callback();
        } else {
          callback("手机号有误");
        }
      } else {
        if (/^\w{3,12}$/g.test(value)) {
          callback();
        } else {
          callback(new Error("请输入正确的账号"));
        }
      }
    };
    const checkCaptcha = (rule, value, callback) => {
      if (/^\d{6}$/g.test(value)) {
        callback();
      } else {
        callback(new Error("请输入正确验证码"));
      }
    };
    return {
      disabled: false,
      tips: "获取验证码",
      t: null,
      form: {
        account: "",
        captcha: "",
      },
      rules: {
        account: [{ validator: checkaccount, trigger: "blur" }],
        captcha: [
          {
            validator: checkCaptcha,
            trigger: "blur",
          },
        ],
      },
    };
  },

  methods: {},
};
</script>
<style lang="scss" scoped>
.login-sms {
  width: 100%;
  height: 100%;
  background: #2d3a4b;
  display: flex;
  justify-content: center;
  align-items: center;

  .el-form {
    width: 300px;
    text-align: center;
    h1 {
      color: #fff;
      font-size: 32px;
    }

    .el-form-item {
      .el-button {
        width: 100%;
      }
    }

    ::v-deep .captcha .el-input-group__append,
    .el-input-group__prepend {
      padding: 0px;
      padding-right: 35px;
    }
  }
}
</style>
